package com.jams.goodox.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jams.goodox.R;
import com.jams.goodox.entity.RechargeRedPacketsInfo;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 充值返还红包
 * Created by Computer on 2016/5/31.
 */
public class RechargeBackRedPackageAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    private List<RechargeRedPacketsInfo.DataBean> infos;
    Context context;

    public RechargeBackRedPackageAdapter(Context context, List<RechargeRedPacketsInfo.DataBean> infos) {
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.infos = infos;
    }

    @Override
    public int getCount() {
        return infos.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final RechargeRedPacketsInfo.DataBean info = infos.get(position);
        final ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.recharge_back_red_package, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvRedPackageCounts.setText("￥" + info.getRedPacketMoney());
        if (info.getType().equals("1")) {
            viewHolder.tvType.setText("通用红包");
            viewHolder.tvIntroduce.setText("任意抵扣");
        } else if (info.getType().equals("2")) {
            viewHolder.tvType.setText("商家红包");
            viewHolder.tvIntroduce.setText("限" + info.getSubName() + "使用");
        }
        return convertView;
    }

    class ViewHolder {
        @Bind(R.id.tv_red_package_counts)
        TextView tvRedPackageCounts;
        @Bind(R.id.tv_type)
        TextView tvType;
        @Bind(R.id.tv_introduce)
        TextView tvIntroduce;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}